package com.ruoyi.web.controller.warning;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warning.domain.dto.ConfigurationDTO;
import com.ruoyi.warning.domain.query.ConfigurationQuery;
import com.ruoyi.warning.service.IConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/warning/configuration")
@Api(tags = "告警配置", description = "用于处理告警配置相关操作的控制器")
public class ConfigurationController {
    @Resource
    private IConfigurationService iConfigurationService;

    @ApiOperation("分页")
    @Log(title = "查询告警配置", businessType = BusinessType.SELECT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/page")
    public R<TableDataInfo> page(ConfigurationQuery query) {
        return R.ok(iConfigurationService.getConfigurationPage(query));
    }

    @ApiOperation("列表")
    @Log(title = "查询告警配置", businessType = BusinessType.SELECT)
//@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/list")
    public R list(ConfigurationQuery query) {
        return R.ok(iConfigurationService.getConfigurationList(query));
    }
    @ApiOperation("详情")
    @Log(title = "告警配置详情", businessType = BusinessType.SELECT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/details/{id}")
    public R getDetails(@PathVariable String id) {
        return R.ok(iConfigurationService.getDetails(id));
    }

    @ApiOperation("新增")
    @Log(title = "新增告警配置", businessType = BusinessType.INSERT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @PostMapping(value = "/save")
    public R saveConfiguration(@RequestBody ConfigurationDTO configuration) {
        return R.ok(iConfigurationService.saveConfiguration(configuration));
    }

    @ApiOperation("删除")
    @Log(title = "删除告警配置", businessType = BusinessType.DELETE)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @PostMapping (value = "/delete")
    public R deleteConfiguration(@RequestBody List<String> ids) {
        return R.ok(iConfigurationService.deleteConfiguration(ids));
    }
    @ApiOperation("修改")
    @Log(title = "修改告警配置", businessType = BusinessType.UPDATE)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @PutMapping (value = "/update")
    public R updateConfiguration(@RequestBody ConfigurationDTO configuration) {
        return R.ok(iConfigurationService.updateConfiguration(configuration));
    }

    @ApiOperation("发送")
    @Log(title = "发送告警", businessType = BusinessType.OTHER)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping (value = "/warning")
    public R warning(List<String> ids) throws Exception {
        return R.ok(iConfigurationService.warning(ids));
    }

    @ApiOperation("获取不可配置的月份")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping (value = "/getMonth/{id}")
    public R getMonth(@PathVariable String id){
        return R.ok(iConfigurationService.getMonth(id));
    }

}
